package com.yjt.fresh.adpater;

import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yjt.fresh.R;
import com.yjt.fresh.bean.BeanHomePage;
import com.yjt.fresh.bean.BeanProduct;
import com.yjt.fresh.service.Utils;

import java.util.List;

/**
 * 首页热门商品
 * Created by mcc on 2018/6/10.
 */

public class AdpRvMainAtyHomePageHot extends BaseQuickAdapter<BeanProduct, BaseViewHolder> {
    public AdpRvMainAtyHomePageHot(int layoutResId, @Nullable List<BeanProduct> data) {
        super(layoutResId, data);
    }

    private double mLatitude;
    private double mLongitude;

    public void setLocation(double latitude, double longitude) {
        mLatitude = latitude;
        mLongitude = longitude;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder helper, BeanProduct item) {
        ImageView iv = helper.getView(R.id.ivAppItemHomePageHot);
        TextView tvTitle = helper.getView(R.id.tvAppItemHomePageHotTitle);
        TextView tvPriceNew = helper.getView(R.id.tvAppItemHomePageHotNew);
        TextView tvPriceOld = helper.getView(R.id.tvAppItemHomePageHotOld);
        TextView tvSaleCount = helper.getView(R.id.tvAppItemHomePageHotSaleCount);
        TextView tvDistance = helper.getView(R.id.tvAppItemHomePageHotDistance);

        Glide.with(mContext).load(item.getONE_IMG()).into(iv);
        tvTitle.setText(item.getTITLE());
        tvPriceNew.setText(item.getDISPLAY_SINGLE_PRICE());
        tvPriceOld.setText("¥  " + item.getDISPLAY_PRICE());
        tvSaleCount.setText("已售:   " + (item.getGROUP_COUNT() == null ? "" : item.getGROUP_COUNT()));
        if (item.getSTORE_LATITUDE_LONGITUDE() != null) {
            String[] location = item.getSTORE_LATITUDE_LONGITUDE().split(",");

            if (mLatitude != 0 && mLongitude != 0) {
                double distance = Utils.getDistance(mLongitude, mLatitude, Double.valueOf(location[0]), Double.valueOf(location[1]));
                tvDistance.setText(distance + "km");
            }
        }else {
            tvDistance.setText(0.00 + "km");
        }
    }
}
